package org.advanced.io;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * @author John.zhang
 * @version Id: Convert, v 1.0 2020/12/14 14:39 ZhiYong Exp $
 * 字符的转化
 */
public class Convert {

    public static void main(String[] args) {
        //对字符流进行缓冲流的包装
        try (BufferedInputStream bufferedInputStream =
                     new BufferedInputStream(new FileInputStream("C:/data/io/io03.txt"));
             InputStreamReader inputStreamReader = new InputStreamReader(bufferedInputStream,StandardCharsets.UTF_8);
             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
            //BufferedReader字符输出流可以基于一行读取输出，不需要复杂的输出逻辑
            System.out.println(bufferedReader.readLine());

            //字符转化流
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream("C:/data/io/io03.txt"), StandardCharsets.UTF_8);
            BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
            bufferedWriter.write("你好，咕咆");
            bufferedWriter.flush();

            /*int i = 0;
            char[] chars = new char[1024];
            while ((i = bufferedReader.read(chars)) != -1) {
                System.out.println(new String(chars, 0, i));
            }*/

        } catch (Exception e) {

        }
    }

}
